package top.hzy520.jms;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Component;
import top.hzy520.email.service.EmailService;
import top.hzy520.email.service.QqEmailService;
import top.hzy520.sms.service.MiaoDiSmsService;

import javax.jms.Destination;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 21:58 2018/5/28
 */
@Component("smsProcessor")
public class MessageProcessor {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Autowired
    private MiaoDiSmsService miaoDiSmsService;

    @Autowired
    private QqEmailService emailService;
    public void sendMesasageToQueue(Destination destination,String message){
        jmsMessagingTemplate.convertAndSend(destination,message);
    }
    @JmsListener(destination = "sms.queue")
    public void sendSmsMesage(String message){
         JSONObject jsonObject= JSON.parseObject(message);
     miaoDiSmsService.sendSms(jsonObject.getString("mobile"),jsonObject.getString("tplId"),jsonObject.getString("param"));
    }
    @JmsListener(destination = "email.queue")
    public void sendEmailMessage(String mesage){
      JSONObject jsonObject=  JSON.parseObject(mesage);
        emailService.sendEmailToQueue(jsonObject.getString("email"),jsonObject.getString("code"));
    }
}
